(in-package :wsml2reasoner)
;;;; $Id$

(let ((wsml-reasoner-factory 
       (#"getFactory" 'DefaultWSMLReasonerFactory)))
  (defun get-wsml-reasoner-factory ()
    "Return reference to the WSMLReasonerFactory singleton."
    wsml-reasoner-factory))

;;; NB parameter is ignored: only works for "IRIS" 
(defun get-reasoner-params (&optional (reasoner "IRIS"))
  "Get a HashMap of parameters suitable for creating a reasoner."
  (let ((params (new 'java.util.Hashtable)))
    (#"put" params
	    (jfield-raw (jobject-class (get-wsml-reasoner-factory))
			"PARAM_BUILT_IN_REASONER")
	    (jenum reasoner
		   "org.wsml.reasoner.api.WSMLReasonerFactory$BuiltInReasoner"))
    (#"put" params
	    (jfield-raw (jobject-class (get-wsml-reasoner-factory))
			  "PARAM_EVAL_METHOD")
	    (new 'Integer 2))
    params))

(defun ask (ontology expression-factory question)
  (let ((query 
	  (#"createLogicalExpression" expression-factory 
				      question ontology))
	(params (get-reasoner-params)))
    (let ((reasoner 
	   (#"createWSMLFlightReasoner" (get-wsml-reasoner-factory)
					params)))
      (#"registerOntology" reasoner ontology)
      (values 
       (#"executeQuery" reasoner (#"getIdentifier" ontology) query)
       ontology))))
    
;;; ?!? Doesn't work; what was it supposed to do?
(defmacro definstance (&keywords name &rest body)
  (with-gensyms (x)
    `(defclass ,name ,(#"memberOf" (first body))
       (loop :for reference :in  body
	  :until (null (first body))
	  :collecting (mklist (introspect-type reference))))))
